package com.diver.flinkdemo.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.diver.flinkdemo.entity.xxt.PolygonFence;
import com.diver.flinkdemo.mapper.mysqlMapper.PolygonFenceMapper;
import com.diver.flinkdemo.service.IPolygonFenceService;
import com.diver.flinkdemo.utils.DynamicDataSourceUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

//@Service
@Slf4j
public class PolygonFenceServiceImpl implements IPolygonFenceService {

    private PolygonFenceMapper mapper;
    private SqlSession session;

    @Override
    public List<PolygonFence> getPolygonFenceByStuId(String studentCardId) {
        try {
            session = DynamicDataSourceUtil.mysqlSessionFactory.openSession();
            mapper = session.getMapper(PolygonFenceMapper.class);
            if (StringUtils.isNotBlank(studentCardId)) {
                QueryWrapper<PolygonFence> qw = new QueryWrapper<>();
                qw.eq("student_card_id", studentCardId);
                List<PolygonFence> list = mapper.selectList(qw);
                return list;
            }
            return null;
        } finally {
            endOfSession(session);
        }
    }
    public void endOfSession(SqlSession session) {
        //关闭sqlSession
        if (session != null) {
            log.info("session commit -> session close");
//            session.commit();
            session.close();
        }
    }
}
